<?php
	
	if ( isset($pages) ) {
		$curPage 	= $pages['current'];
		$totalPage	=	$pages['total'];
		array_push($pages['linked_page'], 1);
	
		$startPage = ($curPage < 5)? 1 : $curPage - 4;
		$endPage = 8 + $startPage;
		$endPage = ($totalPage < $endPage) ? $totalPage : $endPage;
		$diff = $startPage - $endPage + 8;
		$startPage -= ($startPage - $diff > 0) ? $diff : 0;

		if ($startPage > 1) {
			echo "<li>";
			echo $this->Html->link("First", $pages['linked_page']);
			echo "</li><li><a>...</a></li>";
		}
		for($i=$startPage; $i<=$endPage; $i++) {
			$pages['linked_page'][0] = $i;
			//echo "<li><a href='#'>{$i}</a></li>";
			echo "<li>";
			echo $this->Html->link("{$i}", $pages['linked_page']);
			echo "</li>";
			}
	
		$pages['linked_page'][0] = $totalPage;
	

		if ($endPage < $totalPage) {
			echo "<li><a>...</a></li><li>";
			echo $this->Html->link("Last", $pages['linked_page']);
			echo "</li>";
		}
	} 

?>
<!--
<li class="disabled"><a href="#">Prev</a></li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
-->